package cn.zhf.shop.controller;

import cn.zhf.shop.entity.Campus;
import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.search.CampusSearch;
import cn.zhf.shop.entity.search.OrderSearch;
import cn.zhf.shop.service.CampusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.security.MessageDigest;
import java.util.List;

@RestController
@Api(tags = "校区模块")
@RequestMapping("/api/campus")
public class CampusController {

    @Resource
    private CampusService campusService;

//
//    Message<?> updateCampusById(Integer id,Campus c);


    @PostMapping("/add")
    @ApiOperation(value = "增加校区")
    public Message<?> addCampus(Campus c, MultipartFile file){

        return campusService.addCampus(c);
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有校区")
    public Message<List<Campus>> getAllCampus(){
        return campusService.getAllCampus();
    }

    @GetMapping("/id")
    @ApiOperation(value = "根据Id获取校区详情")
    public Message<Campus> getCampusById(Integer id){
        return campusService.getCampusById(id);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "根据id删除校区")
    public Message<?> deleteCampusById(Integer id){
        return campusService.deleteCampus(id);
    }

    @GetMapping("/orgId")
    @ApiOperation(value = "根据机构编号获取校区列表")
    public Message<List<Campus>> getCampusByOrgId(Integer orgId){
        return campusService.getCampusByOrgId(orgId);
    }

    @GetMapping("/city")
    @ApiOperation(value = "根据城市获取校区列表")
    public Message<List<Campus>> getCampusByCity(String city){
        return campusService.getCampusByCity(city);
    }

    @GetMapping("/search")
    @ApiOperation(value = "根据校区名获取校区列表")
    public Message<List<Campus>> searchCampusByName(String name){
        return campusService.searchCampusByName(name);
    }

    @PostMapping("/updateState")
    @ApiOperation(value = "更新校区状态")
    public Message<?> updateStateById(Integer id,Integer state){
        return campusService.updateCampusState(id, state);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新校区信息")
    public Message<?> update(Integer id,Campus c){
        return campusService.updateCampusById(id, c);
    }

    @ApiOperation(value = "根据head查campus信息")
    @GetMapping("/head")
    public Message<List<Campus>> selectByHead(Integer head){
        return campusService.selectByHead(head);
    }

    @ApiOperation(value = "模糊查询")
    @GetMapping("/search2")
    public Message<List<Campus>> search2(Integer userid,String str){
        return campusService.search2(userid,str) ;
    }

    @ApiOperation(value = "精确查询")
    @GetMapping("/search1")
    public Message<List<Campus>> search1 (Integer userid,String campusName,String provice){
        return campusService.search1(userid,campusName,provice);
    }

    @ApiOperation(value = "多条件组合模糊查询")
    @PostMapping("/mohu/condition/search")
    public Message mohuConditionSearch(CampusSearch c){
        return campusService.mohuConditionSearch(c);
    }

    @ApiOperation(value = "根据推荐人id返回所有校区")
    @GetMapping("/referenceId/Allcampus")
    public Message getAllcampusByreferenceId(int referenceId){
        return campusService.getAllcampusByreferenceId(referenceId);
    }
}
